package com.tangye.massageshop.exception;

import com.tangye.massageshop.util.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Log4j2
@RestControllerAdvice
public class GlobalExceptionAdvice {

    @ExceptionHandler(ShopException.class)
    public Result handleShopException(ShopException e) {
        return Result.error(e.getMessage());
    }

    // 未知异常
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        log.error(e.getMessage(),e);
        return Result.error(e.getMessage());
    }

}
